package bpm.dao.impl.document;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import bpm.domain.document.Attachment;

public class AttachmentBatchPreparedStatementForUpdate implements
		BatchPreparedStatementSetter {

	private List<Attachment> attachments;

	public AttachmentBatchPreparedStatementForUpdate(
			List<Attachment> attachments) {
		this.attachments = attachments;
	}

	public AttachmentBatchPreparedStatementForUpdate() {
	}

	public int getBatchSize() {
		return attachments.size();
	}

	public void setValues(PreparedStatement ps, int i) throws SQLException {
		ps.setInt(1, attachments.get(i).getType().getId());
		ps.setString(2, attachments.get(i).getReferencedResourceType().name());
		ps.setString(3, attachments.get(i).getReferencedResourceId());
		ps.setString(4, attachments.get(i).getOwnedDocument().getId());
		ps.setString(5, attachments.get(i).getPaperString());
		ps.setString(6, attachments.get(i).getTitle());
		ps.setInt(7, attachments.get(i).getSize());
		ps.setString(8, attachments.get(i).getLastUpdater().getId());
		ps.setString(9, attachments.get(i).getLastUpdater().getName());
		ps.setTimestamp(10, new java.sql.Timestamp(attachments.get(i).getLastUpdateTime()
				.getTime()));
		ps.setString(11, attachments.get(i).getDescription());
		ps.setString(12, attachments.get(i).getScope());
		ps.setString(13, attachments.get(i).getId());
	}
}
